<?php 
	$khachhang=replatestring($_POST['Kha_Id'],false);
	$kh_id=$_POST['kh_id'];
	if($khachhang==""){$khachhang=$kh_id;}
	
	$ngaythu=replatestring($_POST['ngaythu'],false);
	$sotien=replatestring($_POST['sotien'],false);

	$diengiai=replatestring($_POST['diengiai'],false);
	
	$thoigian=time();
	$nguoicapnhat=$_SESSION['userid'];
	$id=$_POST['id'];
?>

<?php 

$data=false;
if($khachhang!=="" and $sotien!==""){$data=true;}
if($data==true){
	if($id=="")
	{
	mysql_query("insert into thu_chi
	(kh_id,sotien,time,description,user_update,time_update,type)
value('$khachhang','$sotien','$ngaythu','$diengiai','$nguoicapnhat','$thoigian','1')
				");
	
	
		$cauthongbao="Thêm thành công";
		$link=$url_main_site."system/index.php?tn=contract&hd=phieuthu_list";
		thongbao($cauthongbao,$link);
	}
	else
	{
		mysql_query("
					update thu_chi set
						kh_id = '$khachhang',
						sotien = '$sotien',
						time ='$ngaythu',
						description ='$diengiai',
						user_update = '$nguoicapnhat',
						time_update = '$thoigian'
					where id ='$id'
						
		");
		
			$cauthongbao="Bạn đã sửa thành công";
			$link=$url_main_site."system/index.php?tn=contract&hd=phieuthu_list";
			thongbao($cauthongbao,$link);
	}
}
else
{
		$cauthongbao="Dữ liệu không hợp lệ";
		$link=$url_main_site."system/index.php?tn=contract&hd=phieuthu_list";
		thongbao($cauthongbao,$link);
}
?>